package edu.biwu.response;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.util.Date;

/**
 * 设置响应头:
 *     public void addHeader(String name, String value):可以添加响应头,一个响应头的key可以对应多个value(或者说可以设置多个name相同的响应头)
 *    public void setHeader(String name, String value):设置响应头,如果已经设置相同name的响应头,新的value值会覆盖老的value值(类似HashMap)
 *     public void setDateHeader(String name, long date):设置一个日期相关的响应头
 */
@WebServlet("/resp/demo02")
public class ResponseDemo02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.addHeader("name","zhangsan");
        response.addHeader("name","lisi");
        response.setHeader("name","wangyu");

        response.setDateHeader("Date",new Date().getTime());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
